package com.ocean.recommendationserver.realtimerecommend.crawl;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class WebClientHeader {
	private static List<String> userAgent;
	
	private static List<String> connection;
	
	private static List<String> accept;
	
	private static List<String> acceptEncoding;
	
	private static List<String> acceptLanguage;

	private static List<String> charsert;
	
	private static Random rand = new Random();
	

	public static String getConnection(){
		if (connection==null) {
			connection = new ArrayList<String>();
			connection.add("close");
			connection.add("Keep-Alive");
		}
		return connection.get(rand.nextInt(connection.size()));
	}
	
	public static String getAccept(){
		if (accept==null) {
			accept = new ArrayList<String>();
			accept.add("text/html,application/xhtml+xml,application/xml;q=0."+randNum(5, 4)+",image/webp,image/apng,*/*;q=0."+randNum(1, 4));
			accept.add("text/html;q=0."+randNum(5, 4)+",*/*;q=0."+randNum(1, 4));
		}
		return accept.get(rand.nextInt(accept.size()));
	}
	
	public static String getAcceptEncoding(){
		if (acceptEncoding==null) {
			acceptEncoding = new ArrayList<String>();
			acceptEncoding.add("identity; q=0."+randNum(5, 4)+", *;q=0."+randNum(1, 4));
			acceptEncoding.add("deflate; q=0."+randNum(5, 4)+",*;q=0."+randNum(1, 4));
		}
		return acceptEncoding.get(rand.nextInt(acceptEncoding.size()));
	}
	
	public static String getAcceptLanguage(){
		if (acceptLanguage==null) {
			acceptLanguage = new ArrayList<String>();
			acceptLanguage.add("zh-CN,zh;q=0."+randNum(5, 4));
			acceptLanguage.add("zh-CN,zh;q=0."+randNum(5, 4)+",en-us,en;q=0."+randNum(1, 4));
			acceptLanguage.add("en-us,en;q=0."+randNum(3, 4));
		}
		return acceptLanguage.get(rand.nextInt(acceptLanguage.size()));
	}
	
	public static String getCharsert(){
		if (charsert==null) {
			charsert = new ArrayList<String>();
			charsert.add("UTF-8");
		}
		return charsert.get(rand.nextInt(charsert.size()));
	}
	
	public static String getUserAgent(){
		if (userAgent==null) {
			userAgent = new ArrayList<String>();
			userAgent.add("Mozilla/5.0 (Windows NT 5.2) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30");
			userAgent.add("Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36");
			userAgent.add("Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.84 Safari/535.11 SE 2.X MetaSr 1.0");
			userAgent.add("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SV1; QQDownload 732; .NET4.0C; .NET4.0E; SE 2.X MetaSr 1.0)");
			userAgent.add("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:16.0) Gecko/20121026 Firefox/16.0");
			userAgent.add("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:2.0b13pre) Gecko/20110307 Firefox/4.0b13pre");
			userAgent.add("Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15");
			userAgent.add("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11");
			userAgent.add("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.133 Safari/534.16");
			userAgent.add("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)");
			userAgent.add("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
			userAgent.add("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0");
			userAgent.add("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1");
			userAgent.add("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1092.0 Safari/536.6");
			userAgent.add("Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6");
			userAgent.add("Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/19.77.34.5 Safari/537.1");
			userAgent.add("Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.36 Safari/536.5");
			userAgent.add("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3");
			userAgent.add("Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3");
			userAgent.add("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3");
			userAgent.add("Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1062.0 Safari/536.3");
			userAgent.add("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1062.0 Safari/536.3");
			userAgent.add("Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3");
			userAgent.add("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3");
			userAgent.add("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3");
			userAgent.add("Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.0 Safari/536.3");
			userAgent.add("Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/535.24 (KHTML, like Gecko) Chrome/19.0.1055.1 Safari/535.24");
		}
		return userAgent.get(rand.nextInt(userAgent.size()));
	}
	
	
	private static int randNum(int min,int randNum){
		return rand.nextInt(randNum)+min;
	}
}
